package com.bsj.travel.device.web.controller;

import com.bsj.travel.def.common.DTO.web.subscribe.SubscribeDTO;
import com.bsj.travel.def.common.DTO.web.subscribe.SubscribeSearchDTO;
import com.bsj.travel.def.common.VO.SubscribeVO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.device.service.SubscribeService;
import com.bsj.travel.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @description SubscribeController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/2/27 11:35
 **/
@RestController
@RequestMapping("/subscribe")
public class SubscribeController {

    @Autowired
    private SubscribeService subscribeService;


    /**
     * 添加订阅
     *
     * @param subscribeDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/2/27 11:52
     */
    @PostMapping("/add")
    @RequiresPermissions(value = "subscribe:operation:add")
    public JsonResult add(@Validated SubscribeDTO subscribeDTO) {
        return subscribeService.addSubscribe(subscribeDTO);
    }

    /**
     * 删除订阅
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/2/27 11:52
     */
    @PostMapping("/delete/{id}")
    @RequiresPermissions(value = "subscribe:operation:delete")
    public JsonResult delete(@PathVariable Long id) {
        return subscribeService.deleteSubscribe(id);
    }

    /**
     * 修改订阅
     *
     * @param subscribeDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/2/27 11:52
     */
    @PostMapping("/update")
    @RequiresPermissions(value = "subscribe:operation:update")
    public JsonResult update(@Validated SubscribeDTO subscribeDTO) {
        return subscribeService.updateSubscribe(subscribeDTO);
    }

    /**
     * 根据订阅id获取订阅信息
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult<com.bsj.travel.def.common.VO.SubscribeVO>
     * @author ljx
     * @time 2024/2/27 11:53
     */
    @GetMapping("/getById/{id}")
    @RequiresPermissions(value = "subscribe:info:getById")
    public JsonResult<SubscribeVO> getById(@PathVariable("id") Long id) {
        SubscribeVO subscribeVO = subscribeService.getSubscribeInfoById(id);
        return JsonResult.success(subscribeVO);
    }

    /**
     * 订阅分页
     *
     * @param subscribeSearchDTO
     * @return com.bsj.travel.def.global.JsonResult<java.util.List < com.bsj.travel.def.common.VO.SubscribeVO>>
     * @author ljx
     * @time 2024/2/27 11:53
     */
    @GetMapping("/page")
    @RequiresPermissions(value = "subscribe:info:page")
    public JsonResult<List<SubscribeVO>> page(@Validated SubscribeSearchDTO subscribeSearchDTO) {
        return subscribeService.pageSubscribe(subscribeSearchDTO);
    }
}
